package com.umeng.comm.ui.activities;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

import com.qianxx.base.BaseAty;
import com.qianxx.base.utils.ToastUtil;
import com.qianxx.draw.R;

/**
 * Created by summersoft on 2016/5/5.
 */
public class TeachActivity extends BaseAty {

    private EditText mTvname;

    public static final String GUIDE = "name";
    public static final int Result_Guide = 1;

    private String name;

    @Override
    protected void onCreate(Bundle arg0) {
        super.onCreate(arg0);
        setContentView(R.layout.teach);
        name = getIntent().getStringExtra(GUIDE);
        initView();
        mTvname.setText(name);
        mTvname.setSelection(mTvname.getText().toString().length());
    }

    @Override
    public void topRightClick(View v) {
        super.topRightClick(v);
        if (invalid()) {
            Intent data = new Intent();
            data.putExtra(GUIDE, mTvname.getText().toString());
            setResult(Result_Guide, data);
            finish();
        }

    }

    private boolean invalid() {
        if (mTvname.getText().length() > 6) {
            ToastUtil.getInstance().toast("指导老师不能超过6个字符");
            return false;
        }
        return true;
    }


    private void initView() {
        showTopRight("确定");
        mTvname = (EditText) findViewById(R.id.teach_name);
    }

    public static void actionStart(Activity context, String name, int requestCode) {
        Intent intent = new Intent(context, TeachActivity.class);
        intent.putExtra(GUIDE, name);
        context.startActivityForResult(intent, requestCode);
        context.overridePendingTransition(0, 0);
    }
}
